TOOL.Category = "Pulse Fegyverek"
TOOL.Name = "#Pulsed Beam Gun"
TOOL.Command = nil
TOOL.ConfigName = ""
TOOL.Tab = "WUW Weaponry"

TOOL.ClientConVar["DamageType"] = "normal"
TOOL.ClientConVar["R"] = 255
TOOL.ClientConVar["G"] = 255
TOOL.ClientConVar["B"] = 255
TOOL.ClientConVar["AutoWeld"] = "0"
TOOL.EntityClass = "Weapon"

if (SERVER) then
	CreateConVar('sbox_maxbeam_pulsed', 2)
end

if ( CLIENT ) then
	language.Add( "Tool_beam_pulsed_name", "Pulsed Beam Gun" )
	language.Add( "Tool_beam_pulsed_desc", "Fires a Simple beam" )
	language.Add( "Tool_beam_pulsed_0", "Left-Click to Spawn Weapon" )
	
	language.Add( "Undone_beam_pulsed", "Undone Pulsed Beam Gun" )
	
	language.Add( "Cleanup_beam_pulsed", "Cleanup Pulsed Beam Guns" )
	language.Add( "Cleaned_beam_pulsed", "Cleaned up all Pulsed Beam Guns" )
	language.Add( "SBoxLimit_beam_pulsed", "Reached the Pulsed Beam Limit" )
end

function TOOL:SpawnEntity(entity, position, trace)
	local newentity = ents.Create(entity)
	newentity:SetPos(position)
	newentity:SetAngles( trace.HitNormal:Angle() + Angle(90,0,0))
	newentity.Color = Color(self:GetClientNumber("R"), self:GetClientNumber("G"), self:GetClientNumber("B"))
	newentity.DamageType = self:GetClientInfo("DamageType")
	newentity:SetPlayer(self:GetOwner())
	newentity:Spawn()
	
	if util.tobool(self:GetClientNumber("AutoWeld")) then
		local phys = newentity:GetPhysicsObject()  	
		if (phys:IsValid()) then  		
			local weld = constraint.Weld(newentity, trace.Entity, 0, trace.PhysicsBone, 0)
			local nocollide = constraint.NoCollide(newentity, trace.Entity, 0, trace.PhysicsBone)
		end 
	end
	
	self:GetOwner():AddCount( "beam_pulsed", newentity ) 
	
	undo.Create("beam_pulsed")
		undo.AddEntity( newentity )
		undo.AddEntity( weld )
		undo.AddEntity( nocollide )
		undo.SetPlayer( self:GetOwner() )
	undo.Finish()
end

function TOOL:LeftClick( trace )
if (CLIENT) then return true end
if ( !trace.Hit ) then return end
local ply = self:GetOwner()
if (!ply:CheckLimit( "beam_pulsed" )) then return end
	
	if ( SERVER && !util.IsValidPhysicsObject( trace.Entity, trace.PhysicsBone ) ) then return false end
	
	local SpawnPos = trace.HitPos-- + trace.HitNormal * 100
	self:SpawnEntity( "weapon_beam_pulsed", SpawnPos, trace)
	return true

end

if CLIENT then
local options = {}
options["Normal Sebzes"] = {beam_pulsed_DamageType = "normal"}
options["Anti-Pajzs (Csak pajzsot sebez)"] = {beam_pulsed_DamageType = "anti-shield"}
options["Robbanto (Nem sebez pajzsot)"] = {beam_pulsed_DamageType = "destructive"}

function TOOL.BuildCPanel( CPanel )
	CPanel:ClearControls()
	CPanel:AddHeader()
	CPanel:AddDefaultControls()
	// HEADER
	CPanel:AddControl( "Header", { Text = "#Tool_beam_pulsed_name", Description = "#Tool_beam_pulsed_desc" }  )
	CPanel:AddControl( "CheckBox", { Label = "Autoweld", Command = "beam_pulsed_AutoWeld" } )
	CPanel:AddControl( "ComboBox", { Label = "Damage Type", MenuButton = 0, Options = options})
	CPanel:AddControl( "Color", { Label = "Beam Color", Red = "beam_pulsed_R", Green = "beam_pulsed_G", Blue = "beam_pulsed_B", ShowAlpha = 0, ShowHSV = 1, ShowRGB = 1, Multiplier = 255})
end
end